define(["jquery", "bbcare",
    "scprit/department/vm/assessmentScreening/bsid2.ui.js",
    "scprit/department/vm/assessmentScreening/assessmentScreeningQuestion.servers.js"], function ($,$bb,$ui,$servers) {
    var event = {};
    /*
    * 问卷类型切换：data:后台返回的问卷；stageData:情景的tab列表;monthData:月龄的tab列表；scoreObj:结果存储：
    * */
    event.tabClick = function(data,stageData,monthData,scoreObj){
        var _this = this;
        var i = 0;
        $(".testSelect").off('click','div[group]');
        $(".testSelect").on('click','div[group]',function(){
            var group = $(this).attr("group");
            var lens = $("#tabs>div").length;
            if(group == "prev"){
                if(i==0){i=lens;}
                i = --i;
            }
            if(group == "next"){
                if(i == lens -1){i= -1;}
                i = ++i;
            }
            $("#tabs>div").eq(i).removeClass("hide").addClass("selected-tab").siblings().addClass("hide").removeClass("selected-tab");
            $("#tabs>div").eq(i).click(_this.tabCallback("#tabs>div.selected-tab",data,stageData,monthData,scoreObj));
        });
    };
    event.tabCallback = function(dom,data,stageData,monthData,scoreObj){
        var _this = this;
        $ui.tabsInit({"id":"#ques-tab"});
        var quesType = $(dom).attr("quesType");
        var monthAge = $(dom).attr("monthAge");
        $("#ques-tab>div").click(function(){
            if(!$(this).hasClass("checked")){
                $(this).addClass("checked").siblings().removeClass("checked");
                if($(this).index() == 1){
                    var quesList = _this.quesList(data,quesType);
                    $ui.bsidInit({"id":"#questions","data":quesList});
                    $('#monthList li[class*="checking"]').click();
                }else if($(this).index() == 0){
                    $("#monthList").find("li[group='item'].checking").click();
                }
            }
        });
        if(quesType == "行为"){
            $("#ques-tab,.ques-stage,.node,#userDefinedMonth").css("display","none");// 新增userDefinedMonth
            var behaviorTab = [];
            for(var item in data[quesType]){
                if(data[quesType][item].flag == 1){
                    behaviorTab.push({"item":item,"flag":1});
                }else{
                    behaviorTab.push({"item":item});
                }
            }
            $ui.behaviorTabInit({"id":"#behaviorTab","data":behaviorTab});
            $("#behaviorTab>li.be-selected").click(_this.behaviorTab(data,quesType,scoreObj));
            $("#behaviorTab").on("click","li",function(){
                $(this).addClass("be-selected").siblings().removeClass("be-selected");
                _this.behaviorTab(data,quesType,scoreObj);
            });
        }else{
            $("#ques-tab,.ques-stage,.node,#userDefinedMonth").css("display","block");
            $("#behaviorTab").html("");
            var basicId = $(dom).attr("start");
            var endId = $(dom).attr("end");
            var isEnd = $(dom).attr("isEnd");
            $ui.nodeInit({"id":"#node","data":{"basic":basicId,"max":endId}});
            var startAge = monthAge*1-1 < 0.1 ? 0.1:monthAge*1-1;
            var onTabSelect = function(startAge,quesType){
                var intelStart  = _this.findStart(startAge,monthData,quesType);//获取智力的初始
                var stageS = _this.getStage(intelStart.id,stageData,quesType);
                var intelS = _this.stageShowLength(stageData,quesType,stageS.index);
                var monthS = _this.stageShowLength(monthData,quesType,intelStart.index);
                $ui.stageInit({"id":"#stageList","data":intelS});
                $ui.monthInit({"id":"#monthList","data":monthS});
                _this.stageListClick(data,quesType,stageData);
                _this.monthListClick(data,quesType,stageData,monthData);
                _this.stageTabArr(stageData,quesType,scoreObj,stageS.index);
                _this.stageTabArr2(monthData,quesType,scoreObj,intelStart.index);
                $("#monthList").find('li[group="item"][quesId="'+intelStart.id+'"]').click();
                $("#questions").off("click",".ques-detail .options");
                if(!isEnd){
                    $("#questions").on("click",".ques-detail .options",function(){
                        var index = $(this).index();
                        var value = index == 0 ? 1:0;
                        var stage = $(this).parent("li").attr("stage");
                        var id = $(this).parent("li").attr("id");
                        var quesType = $("#tabs").find("div.selected-tab").attr("quesType");
                        var type = quesType == "智力" ? "intellgence" : quesType == "运动" ? "sports":"behavior";
                        var service = $(this).parent().attr("service"),jumpType = $(this).parent().attr("type");
                        var quesId = service.substring(0,service.indexOf(":"));
                        if(jumpType== "before" ){
                            if(!scoreObj[type][quesId]){
                                $bb.toastShow("请先做第"+quesId+"题",2000);
                                $("#monthList").find('li[group="item"][quesId="'+quesId+'"]').click();
                            }else{
                                if(id.indexOf(".") >= 0){
                                    var idS = id.substring(id.indexOf(".")+1);
                                    scoreObj["sports"][idS] = {
                                        "value":value,
                                        "note":$(this).parent("li").next("li").find("textarea").val()
                                    };
                                    dealFn(data,"运动",stage,monthData,idS,value,"sports");
                                }else{
                                    var flagT;
                                    if(id.indexOf("T")>=0){
                                        id = id.substring(0,id.indexOf("T"));
                                        flagT = "T";
                                    }
                                    scoreObj[type][id] = {
                                        "value":value,
                                        "note":$(this).parent("li").next("li").find("textarea").val()
                                    };
                                    dealFn(data,quesType,stage,monthData,id,value,flagT);
                                }
                                $(this).removeClass("green grey").addClass("green").siblings().removeClass("green grey").addClass("grey");
                            }
                        }else{
                            if(id.indexOf(".") >= 0){
                                var idS = id.substring(id.indexOf(".")+1);
                                scoreObj["sports"][idS] = {
                                    "value":value,
                                    "note":$(this).parent("li").next("li").find("textarea").val()
                                };
                                dealFn(data,"运动",stage,monthData,idS,value,"sports");
                            }else{
                                var flagT;
                                if(id.indexOf("T")>=0){
                                    id = id.substring(0,id.indexOf("T"));
                                    flagT = "T";
                                }
                                scoreObj[type][id] = {
                                    "value":value,
                                    "note":$(this).parent("li").next("li").find("textarea").val()
                                };
                                dealFn(data,quesType,stage,monthData,id,value,flagT);
                            }
                            if( jumpType == "after" || jumpType == "same"){
                                if(!scoreObj[type][quesId]){
                                    $bb.toastShow("请接着做第"+quesId+"题",2000);
                                    $("#questions").find('ul[quesId="'+quesId+'"]').addClass("ques-selected").siblings().removeClass("ques-selected")
                                }
                            }
                            $(this).removeClass("green grey").addClass("green").siblings().removeClass("green grey").addClass("grey");
                        }
                        var number = quesType == "智力" ? 10 : 6;
                        var tpl = {
                            title:"提示",
                            tips:"1-"+number+"题无法完成，最低基础水平无法完成，0分。",
                            btn2:"返回上一题",
                            btn1:"全部重做",
                            btn0:"知道了"
                        };
                        var callFn2 = function(){
                            delete scoreObj[type][id];
                            for(var i= 0;i<data[quesType][stage].length;i++){
                                if(id == data[quesType][stage][i].id){
                                    delete data[quesType][stage][i].value;
                                    delete data[quesType][stage][i].note;
                                }
                            }
                            $("#questions").find('ul[quesId="'+id+'"]').find("li>.options").removeClass("green grey");
                        };
                        var callFn1 = function(){
                            scoreObj[type] = {};
                            for(var item in data[quesType]){
                                for(var i= 0;i<data[quesType][item].length;i++){
                                    delete data[quesType][item][i].note;
                                    delete data[quesType][item][i].value;
                                }
                            }
                            for(var i= 0;i<monthData[quesType].length;i++){
                                if(monthData[quesType][i].value >= 0){
                                    delete monthData[quesType][i].value;
                                }
                            }
                            $("#tabs>div.selected-tab").click(_this.tabCallback("#tabs>div.selected-tab",data,stageData,monthData,scoreObj));
                        };
                        var callFn0 = function(){
                            _this.getBasic(data,stageData,scoreObj,type,id,monthData);
                        };
                        if(id*1 <= number && value == 0){
                            if(jumpType== "before"){
                                if(scoreObj[type][quesId]){
                                    _this.dialog(tpl,callFn2,callFn1,callFn0);
                                }
                            }else{
                                _this.dialog(tpl,callFn2,callFn1,callFn0);
                            }
                        }else{
                            if(idS){
                                _this.getBasic(data,stageData,scoreObj,type,idS,monthData,"sports");
                            }
                            _this.getBasic(data,stageData,scoreObj,type,id,monthData);
                        }
                    });
                }
                $("#questions").on("blur",".ques-detail textarea",function(){
                    var stage = $(this).parent("li").prev().attr("stage");
                    var id = $(this).parent("li").prev().attr("id");
                    var quesType = $("#tabs>div.selected-tab").attr("quesType");
                    if(id.indexOf(".") >= 0){
                        id = id.substring(id.indexOf(".")+1);
                        if(scoreObj["sports"][id]){
                            scoreObj["sports"][id]["note"] =$(this).val();
                        }else{
                            scoreObj["sports"][id] = {"note":$(this).val()}
                        }
                    }else{
                        var type = quesType == "智力" ? "intellgence" : quesType == "运动" ? "sports":"behavior";
                        if(id.indexOf("T")>=0){
                            id = id.substring(0,id.indexOf("T"));
                        }
                        if(scoreObj[type][id]){
                            scoreObj[type][id]["note"] =$(this).val();
                        }else{
                            scoreObj[type][id] = {"note":$(this).val()}
                        }
                    }
                    for(var i= 0;i<data[quesType][stage].length;i++){
                        if(id == data[quesType][stage][i].id){
                            data[quesType][stage][i].note = $(this).val();
                        }
                    }
                });
            };
            onTabSelect(startAge,quesType);
            $("#userDefinedMonth button").click(function(){
                var value = $(this).parents("#userDefinedMonth").find("input").val();
                value = value.replace(/[^0-9\\.]/ig,"");
                startAge = value*1-1 < 0.1 ? 0.1:value*1-1;
                var quesType = $(dom).attr("quesType");
                onTabSelect(startAge,quesType);
            });
        }
    };
    var dealFn = function(data,quesType,stage,monthData,id,value,flag){
        if(flag == "sports"){
            for(var st in data[quesType]){
                for(var i= 0;i<data[quesType][st].length;i++){
                    if(id == data[quesType][st][i].id){
                        data[quesType][st][i].value = value;
                    }
                }
            }
            for(var i= 0;i<monthData["运动"].length;i++){
                if(id == monthData["运动"][i].id){
                    monthData["运动"][i].value = value;
                }
            }
            for(var st in data["智力"]){
                for(var i= 0;i<data["智力"][st].length;i++){
                    if(data["智力"][st][i].mr){
                        if(id == data["智力"][st][i].id){
                            data["智力"][st][i].value = value;
                        }
                    }
                }
            }
        }else{
            var idT = id;
            if(flag =="T"){idT = id+'T';}
            for(var i= 0;i<data[quesType][stage].length;i++){
                if(idT == data[quesType][stage][i].id){
                    data[quesType][stage][i].value = value;
                }
            }
            for(var i= 0;i<monthData[quesType].length;i++){
                if(id == monthData[quesType][i].id){
                    monthData[quesType][i].value = value;
                }
            }
        }
    };
    event.stageListClick = function(data,quesType,stageData,monthData){
        var _this = this;
      $("#stageList").off("click","li[group = 'item']");
      $("#stageList").on("click","li[group = 'item']",function(){
          var quesTabIndex = $("#ques-tab>div.checked").index();
          if(quesTabIndex == 1){
              $("#ques-tab>div").eq(0).click();
              var idArr = JSON.parse($(this).attr("idArr"));
          }
          quesType = $("#tabs>div.selected-tab").attr("quesType");
          if($(this).hasClass("hide")){
              var nowIndex = $(this).attr('index');
              var intelS = _this.stageShowLength(stageData,quesType,nowIndex*1);
              $ui.stageInit({"id":"#stageList","data":intelS});
              $("#stageList").find('li[group="item"][index="'+nowIndex+'"]').addClass("checking");
          }
          $(this).addClass("checking").siblings().removeClass("checking");
          var stage = $(this).attr("stage");
          var index =$(this).attr("index");
          for(var i = 0;i<data[quesType][stage].length;i++){
              data[quesType][stage][i].stage = stage;
          }
          $ui.bsidInit({"id":"#questions","data":data[quesType][stage]});
          if(quesTabIndex == 1){
              $("#questions").find('ul[quesId="'+idArr[0]+'"]').addClass("ques-selected");
          }
      });
    };
    event.monthListClick = function(data,quesType,stageData,monthData){
        var _this = this;
        _this.stageListClick(data,quesType,stageData);
        $("#monthList").on("click","li[group = 'item']",function(){
            if($(this).hasClass("hide")){
                var nowIndex = $(this).attr('quesId');
                var monthS = _this.stageShowLength(monthData,quesType,$(this).attr('quesId')*1);
                $ui.monthInit({"id":"#monthList","data":monthS});
                $("#monthList").find('li[group="item"][quesId="'+nowIndex+'"]').addClass("checking");
            }
            $(this).addClass("checking").siblings().removeClass("checking");
            var quesId = $(this).attr("quesId");
            var stage = $(this).attr("stage");
            var index = $("#ques-tab").find("div.checked").index();
            if(index == 0){
                $("#stageList").find('li[group="item"][stage="'+stage+'"]').click();
                if( $("#questions").find('ul[quesId="'+quesId+'"]').length == 1){
                    $("#questions").find('ul[quesId="'+quesId+'"]').addClass("ques-selected");
                }else{
                    $("#questions").find('ul[quesId="'+quesId+'T"]').addClass("ques-selected");
                }
            }else if(index == 1){
                $("#stageList").find('li[group="item"][stage="'+stage+'"]').addClass("checking").siblings().removeClass("checking"); // add
                var topQues1  = $("#questions").offset().top;
                var topQues2 = 96*quesId;
                var top;
                if(topQues2-topQues1 < 200){
                    top = 0;
                }else{
                    top = topQues2-topQues1;
                }
                $("#questions").find('.question').scrollTop(top);
                if( $("#questions").find('ul[quesId="'+quesId+'"]').length == 1){
                    $("#questions").find('ul[quesId="'+quesId+'"]').addClass("ques-selected").siblings().removeClass("ques-selected");
                }else{
                    $("#questions").find('ul[quesId="'+quesId+'T"]').addClass("ques-selected").siblings().removeClass("ques-selected");
                }
            }
        });
    };
    event.behaviorTab = function(data,quesType,scoreObj){
        var item = $("#behaviorTab>li.be-selected").attr("item");
        var isEnd = $("#tabs>div.selected-tab").attr("isEnd");
        data[quesType][item].item = item;
        $ui.behaviorInit({"id":"#questions","data":data[quesType][item]});
        if(!isEnd){
            $("#questions").off("click",".behavior-option>ul>li");
            $("#questions").off("click",".behavior-other>ul>li");
            $("#questions").on("click",".behavior-option>ul>li",function(){
                var item = $("#behaviorTab>li.be-selected").attr("item");
                if(!$(this).hasClass("be-checked")){
                    $(this).addClass("be-checked").siblings().removeClass("be-checked");
                    var beId = $(this).parents("ul[id]").attr("id");
                    if(!scoreObj["behavior"][beId]){
                        scoreObj["behavior"][beId] = {};
                    }
                    var index = $(this).index();
                    for(var i = 0 ;i<data[quesType][item].questions.length;i++){
                        if(beId == data[quesType][item].questions[i].id){
                            for(var k = 0;k<data[quesType][item].questions[i].response.activity.length;k++){
                                if(k==index){
                                    data[quesType][item].questions[i].response.activity[k].status = 1;
                                }else{
                                    data[quesType][item].questions[i].response.activity[k].status = 0;
                                }
                            }
                            scoreObj["behavior"][beId].activity = $(this).html();
                        }
                    }
                    $("#behaviorTab>li.be-selected").addClass("be-done");
                    data[quesType][item].flag = 1;
                }
            });
            $("#questions").on("blur",".behavior-option>textArea",function(){
                var item = $("#behaviorTab>li.be-selected").attr("item");
                var beId = $(this).parents("ul").attr("id");
                if(!scoreObj["behavior"][beId]){
                    scoreObj["behavior"][beId] = {};
                }
                for(var i = 0 ;i<data[quesType][item].questions.length;i++){
                    if(beId == data[quesType][item].questions[i].id){
                        data[quesType][item].questions[i].responseNote = $.trim($(this).val());
                        scoreObj["behavior"][beId].responseNote = $.trim($(this).val());
                    }
                }
                if($.trim($(this).val())){
                    $("#behaviorTab>li.be-selected").addClass("be-done");
                    data[quesType][item].flag = 1;
                }
            });
            $("#questions").on("click",".behavior-other>ul>li",function(){
                var item = $("#behaviorTab>li.be-selected").attr("item");
                var beId = $(this).parents("ul[id]").attr("id");
                if(!scoreObj["behavior"][beId]){
                    scoreObj["behavior"][beId] = {};
                }
                var index = $(this).index();
                if(!$(this).hasClass("be-checked")){
                    $(this).addClass("be-checked");
                    for(var i = 0 ;i<data[quesType][item].questions.length;i++){
                        if(beId == data[quesType][item].questions[i].id){
                            data[quesType][item].questions[i].append[index].status = 1;
                            if(scoreObj["behavior"][beId].append){
                                scoreObj["behavior"][beId].append.push($(this).html());
                            }else{
                                scoreObj["behavior"][beId].append = [$(this).html()];
                            }
                        }
                    }
                }else{
                    $(this).removeClass("be-checked");
                    for(var i = 0 ;i<data[quesType][item].questions.length;i++){
                        if(beId == data[quesType][item].questions[i].id){
                            data[quesType][item].questions[i].append[index].status = 0;
                            scoreObj["behavior"][beId].append.splice($.inArray($(this).html(),scoreObj["behavior"][beId].append),1);
                        }
                    }
                }
                $("#behaviorTab>li.be-selected").addClass("be-done");
                data[quesType][item].flag = 1;
            });
            $("#questions").on("blur",".behavior-other>textArea",function(){
                var item = $("#behaviorTab>li.be-selected").attr("item");
                var beId = $(this).parents("ul").attr("id");
                if(!scoreObj["behavior"][beId]){
                    scoreObj["behavior"][beId] = {};
                }
                for(var i = 0 ;i<data[quesType][item].questions.length;i++){
                    if(beId == data[quesType][item].questions[i].id){
                        data[quesType][item].questions[i].appendNote = $.trim($(this).val());
                        scoreObj["behavior"][beId].appendNote = $.trim($(this).val());
                    }
                }
                if($.trim($(this).val())){
                    $("#behaviorTab>li.be-selected").addClass("be-done");
                    data[quesType][item].flag = 1;
                }
            });
        }else{
            $(".behavior textarea").each(function(){
                $(this).attr("disabled",true);
            });
        }
    }; 
    //根据题目id查询所属情景：
    event.getStage = function(quesId,stageData,quesType){
        var defaultStage = {};
        for(var i = 0;i<stageData[quesType].length;i++){
            if( stageData[quesType][i].idArr.indexOf(quesId) >= 0 || stageData[quesType][i].idArr.indexOf(quesId+"T") >= 0 ){
                $.extend(defaultStage,stageData[quesType][i]);
                break;
            }
        }
        return defaultStage;
    };
    //原始数据格式处理：
    event.dataDeal = function(data,scoreObj){
        var dt = {};
        for(var item in data){
            var type = item == "运动" ? "sports":item == "智力" ? "intellgence":"behavior";
            if( item == "运动" || item == "智力"){
                dt[item] = {};
                for( var i = 0 ; i< data[item].length;i++){
                    for(var stage in data[item][i]){
                        dt[item][stage] =data[item][i][stage];
                    }
                    for( var j = 0;j<dt[item][stage].length;j++){
                        var id= dt[item][stage][j].id;
                        if(id.indexOf("T")>=0){
                            id=id.substring(0,id.indexOf("T"));
                        }
                        var mr = dt[item][stage][j].mr;
                        if(scoreObj[type][id]){
                            dt[item][stage][j].value = scoreObj[type][id].value;
                            dt[item][stage][j].note = scoreObj[type][id].note;
                        }
                    }
                }
            }
            if(item == "行为"){
                dt[item] = data[item];
                for(var its in dt[item]){
                    //附加记录部分：
                    for(var i= 0;i<dt[item][its].questions.length;i++){
                        var id = dt[item][its].questions[i].id;
                        var append = dt[item][its].questions[i].append;
                        if(append[append.length-1] == "其他"){
                            append.pop();
                            dt[item][its].questions[i].appendOthers = "其他";
                            if(scoreObj[type][id]){
                                dt[item][its].questions[i].appendNote = scoreObj[type][id].appendNote;
                                dt[item][its].flag=1;
                            }
                        }
                        var app = [];
                        for(var j = 0;j<append.length;j++){
                            if(scoreObj[type][id] && scoreObj[type][id].append){
                                if($.inArray(append[j],scoreObj[type][id].append)>=0){
                                    app.push({"check":append[j],"status":1});
                                }else{
                                    app.push({"check":append[j],"status":0});
                                }
                                dt[item][its].flag=1;
                            }else{
                                app.push({"check":append[j]});
                            }
                        }
                        dt[item][its].questions[i].append = app;
                    }
                    //反映部分：
                    for(var i= 0;i<dt[item][its].questions.length;i++){
                        var id = dt[item][its].questions[i].id;
                        if(scoreObj[type][id] && scoreObj[type][id].appendNote){
                            dt[item][its].questions[i].appendNote = scoreObj[type][id].appendNote;
                            dt[item][its].flag=1;
                        }
                        if(dt[item][its].questions[i].response.desc == "儿童在测验时行为的质量"){
                            dt[item][its].questions[i].responseOthers = "请简短的描述该儿童测验时的行为质量";
                        }else if(dt[item][its].questions[i].response.desc == "预测儿童今后的发展，说明理由"){
                            dt[item][its].questions[i].responseOthers = "请简短的预测该儿童今后的发展及理由";
                        }else{
                            var active = dt[item][its].questions[i].response.activity;
                            var ques = [];
                            for(var j = 0;j<active.length;j++){
                                if(scoreObj[type][id] && scoreObj[type][id].activity){
                                    if(scoreObj[type][id].activity == active[j]){
                                        ques.push({"check":active[j],"status":1});
                                    }else{
                                        ques.push({"check":active[j],"status":0});
                                    }
                                    dt[item][its].flag=1;
                                }else{
                                    ques.push({"check":active[j]});
                                }
                            }
                            dt[item][its].questions[i].response.activity = ques;
                            if(dt[item][its].questions[i].id == 2 ||dt[item][its].questions[i].id == 3 || dt[item][its].questions[i].id == 9 || dt[item][its].questions[i].id == 10 || dt[item][its].questions[i].id == 29 || dt[item][its].questions[i].id == 30){
                                dt[item][its].questions[i].classType = "short";
                            }
                        }
                    }
                }
            }
        }
        return dt;
    };
    /*
    * 获取情景的tab列表
    * */
    event.stageList = function(data){
        var stageData = {};
        for(var item in data){
            stageData[item] = [];
            var index = 1;
            for(var val in data[item]){
                var idArr = [];
                for(var i = 0;i<data[item][val].length;i++){
                    var id = data[item][val][i].id;
                    if(data[item][val][i].mr == "mr"){
                        idArr.push("mr"+id);
                    }else{
                        idArr.push(id);
                    }
                }
                stageData[item].push({"stage":val,"idArr":JSON.stringify(idArr),"index":index});
                index++;
            }
        }
        return stageData;
    };

    /*
     * 获取月龄的tab列表
     * */
    event.monthList = function(data,scoreObj){
        var monthData = {};
        for(var item in data){
            monthData[item] = [];
            var type = item == "智力" ? "intellgence" :item == "运动" ? "sports":'';
            for(var val in data[item]){
                for(var i = 0;i<data[item][val].length;i++){
                    if(!data[item][val][i].mr){
                        var id = data[item][val][i].id;
                        if(id.indexOf("T") != "-1"){
                            id = id.substring(0,id.indexOf("T"));
                        }
                        if(scoreObj[type][id] && scoreObj[type][id].value >= 0){
                            var monthObj = {"stage":val,"id":id,"monthAge":data[item][val][i].moonage,"index":id,"value":scoreObj[type][id].value};
                        }else{
                            monthObj = {"stage":val,"id":id,"monthAge":data[item][val][i].moonage,"index":id};
                        }
                        monthData[item][id-1] = monthObj;
                    }
                }
            }
        }
        return monthData;
    };
    /*
    * 讲题目按照序号排列：
    * */
    event.quesList = function(data,quesType){
        var quesList = [];
        for(var val in data[quesType]){
            for(var i = 0;i<data[quesType][val].length;i++){
                if(!data[quesType][val][i].mr){
                    var id = data[quesType][val][i].id;
                    if(id.indexOf("T") != "-1"){
                        id = id.substring(0,id.indexOf("T"));
                    }
                    data[quesType][val][i].stage = val;
                    quesList[id-1] = data[quesType][val][i];
                }
            }
        }
        return quesList;
    };
    /*
     * 查找初始题目：
     * */
    event.findStart = function(intelAge,monthData,quesType){
        var start = {};
        for(var i = 0;i<monthData[quesType].length;i++){
            if(!$.isEmptyObject(monthData[quesType][i])){
                if(monthData[quesType][i].monthAge.indexOf("+")>= 0){
                    if(monthData[quesType][i].monthAge.substring(0,monthData[quesType][i].monthAge.indexOf("+"))*1 > intelAge*1){
                        start = monthData[quesType][i];
                        break;
                    }
                }else{
                    if(monthData[quesType][i].monthAge*1 > intelAge*1){
                        start = monthData[quesType][i-1];
                        break;
                    }else if(monthData[quesType][i].monthAge*1 == intelAge*1){
                        start = monthData[quesType][i];
                        break;
                    }
                }
            }
        }
        return start;
    };
    /*
     * stageTab展示长度：
     * */
    event.stageShowLength = function(listData,quesType,defaultIndex){
        var lens = listData[quesType].length;
        var length = Math.ceil(lens/6);
        for(var i=0;i<listData[quesType].length;i++){
            if(defaultIndex*1 < 6){
                if(listData[quesType][i].index <= 6){
                    listData[quesType][i].showFlag = true;
                }else{
                    listData[quesType][i].showFlag = false;
                }
            }else if((length-1)*6 < defaultIndex && defaultIndex <= length*6){
                if(listData[quesType][i].index > lens-6 ){
                    listData[quesType][i].showFlag = true;
                }else{
                    listData[quesType][i].showFlag = false;
                }
            }else{
                if(listData[quesType][i].index >= defaultIndex*1 && listData[quesType][i].index <= defaultIndex*1 + 5 ){
                    listData[quesType][i].showFlag = true;
                }else{
                    listData[quesType][i].showFlag = false;
                }
            }
        }
        var count = Math.floor(defaultIndex/6);
        return {
            "prev":count,
            "next":count+1,
            "length":length,
            "listData":listData[quesType],
            "quesType":quesType
        };
    };
    event.stageTabArr = function(listData,quesType,scoreObj,startIndex){
        var _this = this,defaultId = 0;
        $("#stageList").off("click","li[group!='item']");
        $("#stageList").on("click","li[group!='item']",function(){
            if(!$(this).hasClass("forbidden")){
                var group = $(this).attr("group");
                var quesType = $(this).attr("quesType");
                var index = $(this).attr("index");
                if(group == "prev"){//渲染前一版
                    defaultId = index*6-5;
                }else if(group == "next"){//渲染后一版
                    defaultId = index*6 + 1;
                }
                var intelS = _this.stageShowLength(listData,quesType,defaultId);
                $ui.stageInit({"id":"#stageList","data":intelS});
                $("#stageList").find('li[group="item"][index="'+defaultId+'"]').click();
            }
        });
    };
    event.stageTabArr2 = function(listData,quesType,scoreObj,startIndex){
        var _this = this,defaultId = 0;
        $("#monthList").off("click","li[group!='item']");
        $("#monthList").on("click","li[group!='item']",function(){
            if(!$(this).hasClass("forbidden")){
                var group = $(this).attr("group");
                var quesType = $(this).attr("quesType");
                var index = $(this).attr("index");
                if(group == "prev"){//渲染前一版
                    defaultId = index*6-5;
                }else if(group == "next"){//渲染后一版
                    defaultId = index*6 + 1;
                }
                var intelS = _this.stageShowLength(listData,quesType,defaultId);
                $ui.monthInit({"id":"#monthList","data":intelS});
                $("#monthList").find('li[group="item"][quesId="'+defaultId+'"]').click();
            }
        });
    };
    /*
    * 判断起始点：data,stageData,monthData,scoreObj
    * */
    event.getBasic = function(data,stageData,scoreObj,type,nowId,monthData,flag){
        var _this = this;
        var level= {};
        var number = type == "intellgence" ? 10 : 6;
        var idArr = [];
        for(var item in scoreObj[type]){idArr.push(item);}
        var minId1 = Math.min.apply(null,idArr);
        var maxId1 = Math.max.apply(null,idArr);
        var startQues = $("#tabs>div.selected-tab").attr("start");
        var endQues = $("#tabs>div.selected-tab").attr("end");
        var startFlag = startQues ? true:false;
        var endFlag = endQues ? true:false;
        level["basic"] = startQues ? startQues:'';
        level["max"] = endQues ? endQues:'';
        var idArrTotal = JSON.parse($("#stageList").find('li[class*="checking"]').attr("idArr"));
        var defaultId = $('#monthList li[class*="checking"]').attr("quesId");//获取情境下的定位题id;
        var defaultIndex= $.inArray(defaultId,idArrTotal);
        if(scoreObj[type][nowId] && scoreObj[type][nowId].value >= 0){
            if(!flag){
                if(scoreObj[type][nowId].value == 0){
                    $("#monthList").find('li[group="item"][quesId="'+nowId+'"]').addClass("done").find("span").html('<i class="fa fa-minus-circle" aria-hidden="true"></i>');
                }else{
                    $("#monthList").find('li[group="item"][quesId="'+nowId+'"]').addClass("transition").find("span").html('<i class="fa fa-check-circle" aria-hidden="true"></i>');
                }
                $("#monthList").find('li[group="item"][quesId="'+nowId+'"]').click();
            }
        }
        var getId;
        var index = $("#ques-tab>div.checked").index();
        if(index == 0){
            //情景下题目跳转判断：
            /*
             * 定位在该情景下可以完成的最大题号：
             * */
            var nowIds=[];
            for(var i = 0;i< idArrTotal.length;i++){
                if(idArrTotal[i].indexOf(".") == -1){
                    if(idArrTotal[i].indexOf("T")>=0){
                        idArrTotal[i] = idArrTotal[i].substring(0,idArrTotal[i].indexOf("T"));
                    }
                    if(scoreObj[type][idArrTotal[i]] && scoreObj[type][idArrTotal[i]].value == 1){
                        nowIds.push(idArrTotal[i]*1);
                    }
                }
            }
            if(nowIds.length>0){
                var maxNowId = Math.max.apply(null,nowIds);
                if($("#questions").find('ul[quesId="'+maxNowId+'"]').length == 1){
                    $("#questions").find('ul[quesId="'+maxNowId +'"]').addClass("ques-selected").siblings().removeClass("ques-selected");
                }else{
                    $("#questions").find('ul[quesId="'+maxNowId +'T"]').addClass("ques-selected").siblings().removeClass("ques-selected");
                }
            }

            //起始点未找到：题目跳转：
            if(!startFlag){
                //定位题目做了，判断是否跳转；
                if(scoreObj[type][defaultId] && scoreObj[type][defaultId].value >=0){
                    var isEnd = true;//判断当前情景题目是否做完：true 做完；false：未做完
                    for(var i = 0;i< idArrTotal.length;i++){
                        var id =idArrTotal[i];
                        if(id.indexOf("mr") == -1){
                            if(id.indexOf("T")>=0){
                                id = id.substring(0,id.indexOf("T"));
                            }
                            if(!scoreObj[type][id]){
                                isEnd = false;
                                break;
                            }
                        }else{
                            if(!scoreObj["sports"][id.substring(id.indexOf("mr")+2)]){
                                isEnd = false;
                                break;
                            }
                        }
                    }
                    if(scoreObj[type][defaultId].value == 0){
                        //定位题不通过：如果为当前情景第一个，则自动跳入上一题；反之定位光标移动到当前情境下的上一题：
                        if(defaultIndex == 0){
                            var flagD = true;
                            for(var i = minId1;i<=maxId1;i++){
                                if(!scoreObj[type][i]){
                                    flagD = false;
                                    getId = i;
                                    break;
                                }
                            }
                            if(flagD){getId = minId1-1;}
                            if(idArr.length > 1){
                                var j = 0;
                                do{
                                    j++;
                                }while(scoreObj[type][nowId-j] && scoreObj[type][nowId-j].value == 1);
                                getId = nowId-j;
                            }
                            $("#monthList").find('li[quesId="'+(getId)+'"]').click();
                        }
                    }
                    if(isEnd){
                        //未找到起始点：情景下进入当前情境下最小题目的前一题的情景：
                        var startId = getInit0(scoreObj,type);
                        if(startId){//存在值为0的题目
                            getId = getInitBefore0(scoreObj,type,idArr);
                        }else{//存储的值全部为1时：题目跳转到最高题目：
                            getId = maxId1+1;
                        }
                        $("#monthList").find('li[group="item"][quesId="'+(getId*1)+'"]').click();
                    }
                }
            }
            //起始点不在，判断是否有起始点：
            if(!startFlag){
                var startId = getInit0(scoreObj,type);
                if(startId){
                    if(startId <= number){
                        $bb.toastShow("基础水平无法达到，当前测试结束");
                        $("#questions").off("click",".ques-detail .options");
                        $("#tabs>div.selected-tab").attr("isEnd","end").find("span").eq(1).html("0");
                    }else{
                        var flag = true;
                        for(var i=startId*1-1;i>=(startId*1-number);i--){
                            if(!scoreObj[type][i] || scoreObj[type][i].value == 0){
                                flag = false;
                                break;
                            }
                        }
                        if(flag){
                            startFlag = true ;
                            $("#tabs>div.selected-tab").attr("start",startId-1);
                            $bb.toastShow("找到基础水平",2000);
                            level["basic"]= startId-1;
                            scoreObj["start"][type] = startId-1;
                            $ui.nodeInit({"id":"#node","data":level});
                            for(var i = startId ;i<=maxId1;i++){
                                if(!scoreObj[type][i]){
                                    getId = i;
                                    break;
                                }
                            }
                            $("#monthList").find('li[group="item"][quesId="'+(getId*1)+'"]').click();
                        }
                    }
                }
            }
            //起始点存在，最高水平不存在：自动跳入中间未做的题目部分
            if( startFlag && !endFlag){
                var isEnd =true;
                for(var i = 0;i< idArrTotal.length;i++){
                    var id =idArrTotal[i];
                    if(id.indexOf("mr") == -1){
                        if(id.indexOf("T")>=0){
                            id = id.substring(0,id.indexOf("T"));
                        }
                        if(id >= level["basic"]*1){
                            if(!scoreObj[type][id]){
                                isEnd = false;
                                break;
                            }
                        }
                    }else{
                        var idSports = id.substring(id.indexOf("mr")+2);
                        if(!scoreObj["sports"][idSports]){
                            isEnd = false;
                            break;
                        }
                    }
                }
                if(isEnd){
                    for(var i = level["basic"]*1;i<=maxId1+1;i++){
                        if(!scoreObj[type][i]){
                            getId = i;
                            break;
                        }
                    }
                    $("#monthList").find('li[group="item"][quesId="'+(getId*1)+'"]').click();
                }
            }
        }else if(index == 1){
            //月龄下题目跳转判断：
            if(!startFlag){
                var startId = getInit0(scoreObj,type);
                if(startId){
                    if(startId <= number){
                        $bb.toastShow("基础水平无法达到，当前测试结束");
                        $("#questions").off("click",".ques-detail .options");
                        $("#tabs>div.selected-tab").attr("isEnd","end").find("span").eq(1).html("0");
                    }else{
                        var flag = true;
                        for(var i=startId*1-1;i>=(startId*1-number);i--){
                            if(!scoreObj[type][i] || scoreObj[type][i].value == 0){
                                flag = false;
                                break;
                            }
                        }
                        if(flag){
                            startFlag = true ;
                            $("#tabs>div.selected-tab").attr("start",startId-1);
                            $bb.toastShow("找到基础水平",2000);
                            level["basic"]= startId-1;
                            scoreObj["start"][type] = startId-1;
                            $ui.nodeInit({"id":"#node","data":level});
                            for(var i = startId ;i<=maxId1;i++){
                                if(!scoreObj[type][i]){
                                    getId = i;
                                    break;
                                }
                            }
                            $("#monthList").find('li[group="item"][quesId="'+(getId*1)+'"]').click();
                        }else{
                            var k= 0;
                            do{
                                k++;
                            }while(scoreObj[type][startId-k] && scoreObj[type][startId-k].value >=0 );
                            $("#monthList").find('li[group="item"][quesId="'+(startId-k)+'"]').click();
                        }
                    }
                }else{
                    var maxMonth =Math.max.apply(null, idArr);
                    $("#monthList").find('li[group="item"][quesId="'+(maxMonth*1)+'"]').click();
                }
                if(startFlag){
                    $("#questions").find("ul[quesId]").each(function(index,value){
                        if(index < level["basic"]*1){
                            $(this).find("li[stage]").find(".options").eq(0).addClass("green").removeClass("grey").siblings().addClass("grey").removeClass("green");
                        }
                    });
                }
            }
            if( startFlag && !endFlag){
                //起始点存在的题型跳转：
                for(var its in scoreObj[type]){
                    if(its*1 == level["basic"]*1){
                        var k= 0;
                        do{
                            k++;
                        }while(scoreObj[type][its*1+k] && scoreObj[type][its*1+k].value >= 0);
                        $("#monthList").find('li[group="item"][quesId="'+(its*1+k)+'"]').click();
                    }
                }
            }
        }
        //起始点存在：判断最高水平点：
        if(startFlag && !endFlag){
            var top;
            for(var item in scoreObj[type]){
                if(item*1 >= level["basic"]*1){
                    if(scoreObj[type][item] && scoreObj[type][item].value>= 0){
                        if(scoreObj[type][item].value == 1){
                            var endId = getEnd0(scoreObj,type,item);
                            if(endId && !endFlag){
                                var flagT = true;
                                for(var i = endId*1;i<(endId*1+number);i++){
                                    if(scoreObj[type][i] && scoreObj[type][i].value>= 0){
                                        if(scoreObj[type][i].value == 1){
                                            flagT = false;
                                            break;
                                        }
                                    }else{
                                        flagT = false;
                                        break;
                                    }
                                }
                                if(flagT){
                                    top= endId-1;
                                }
                            }
                        }
                    }else{
                        break;
                    }
                }
            }
            var quesType = type == "intellgence" ? "智力":"运动";
            if(!endFlag && Math.max.apply(null,idArr) == monthData[quesType].length){
                var maxLength = monthData[quesType].length;
                var endLength = true;
                for(var i = level["basic"]*1 ;i<= maxLength*1;i++){
                    if(!scoreObj[type][i]){
                        endLength = false;
                        break;
                    }
                }
                if(endLength){
                    top = maxLength;
                }
            }
        }
        if(startFlag && top){
            var notQues = type == "intellgence" ? "运动":"智力";
            if($('#tabs>div[quesType="'+notQues+'"]').attr("isEnd") == "end"){
                var tpl = {
                    title:"提示",
                    tips:"智力量表、运动量表已经完成，是否提交？",
                    btn2:"返回上一题",
                    btn1:"去提交",
                    btn0:"进入行为量表",
                    flagColor:1 // 1是绿色
                };
                var callFn2 = function(){
                    delete scoreObj[type][nowId];
                    var quesType = type == "intellgence" ? "智力":"运动";
                    for(var stage in data[quesType]){
                        for(var i= 0;i<data[quesType][stage].length;i++){
                            if(!data[quesType][stage][i].mr){
                                var ids= data[quesType][stage][i].id;
                                if(ids.indexOf("T")>=0){
                                    ids = ids.substring(0,ids.indexOf("T"));
                                }
                                if(nowId*1 == ids){
                                    delete data[quesType][stage][i].value;
                                    delete data[quesType][stage][i].note;
                                }
                            }
                        }
                    }
                    if($("#questions").find('ul[quesId="'+nowId+'"]').length == 1){
                        $("#questions").find('ul[quesId="'+nowId+'"]').find("li>.options").removeClass("green grey");
                    }else{
                        $("#questions").find('ul[quesId="'+nowId+'T"]').find("li>.options").removeClass("green grey");
                    }
                };
                var callFn1 = function(){
                    endFlag = true;
                    level["max"]= top;
                    $("#tabs>div.selected-tab").attr({"end":level["max"],"isEnd":"end"});
                    $("#questions").off("click",".ques-detail .options");
                    scoreObj["end"][type] = level["max"];
                    $ui.nodeInit({"id":"#node","data":level});
                    var score = _this.getScore(scoreObj,type,level["basic"]*1,level["max"]*1);
                    $("#tabs>div.selected-tab").find("span").eq(1).html(score);
                    $("#topbar").find("li").eq(0).click();//父页面按钮点击事件
                };
                var callFn0 = function(){
                    endFlag = true;
                    level["max"]= top;
                    $("#tabs>div.selected-tab").attr({"end":level["max"],"isEnd":"end"});
                    $("#questions").off("click",".ques-detail .options");
                    scoreObj["end"][type] = level["max"];
                    var score = _this.getScore(scoreObj,type,level["basic"]*1,level["max"]*1);
                    $("#tabs>div.selected-tab").find("span").eq(1).html(score);
                    $("#tabs>div").eq(2).removeClass("hide").addClass("selected-tab").siblings().addClass("hide").removeClass("selected-tab");
                    $("#tabs>div").eq(2).click(_this.tabCallback("#tabs>div.selected-tab",data,stageData,monthData,scoreObj));
                };
                _this.dialog(tpl,callFn2,callFn1,callFn0);
            }else{
                var tpl2 = {
                    title:"提示",
                    tips:"当前测试已经找到最高水平，即将进入下一项测试……",
                    btn2:"返回上一题",
                    btn1:"进入"+notQues+"量表",
                    btn0:"取消",
                    flag:1 //1不显示第三个按钮：
                };
                var callFn22 = function(){
                    delete scoreObj[type][nowId];
                    var quesType = type == "intellgence" ? "智力":"运动";
                    for(var stage in data[quesType]){
                        for(var i= 0;i<data[quesType][stage].length;i++){
                            if(!data[quesType][stage][i].mr){
                                var ids= data[quesType][stage][i].id;
                                if(ids.indexOf("T")>=0){
                                    ids = ids.substring(0,ids.indexOf("T"));
                                }
                                if(nowId*1 == ids){
                                    delete data[quesType][stage][i].value;
                                    delete data[quesType][stage][i].note;
                                }
                            }
                        }
                    }
                    if($("#questions").find('ul[quesId="'+nowId+'"]').length == 1){
                        $("#questions").find('ul[quesId="'+nowId+'"]').find("li>.options").removeClass("green grey");
                    }else{
                        $("#questions").find('ul[quesId="'+nowId+'T"]').find("li>.options").removeClass("green grey");
                    }
                };
                var callFn21 = function(){
                    endFlag = true;
                    level["max"]= top;
                    $("#tabs>div.selected-tab").attr({"end":level["max"],"isEnd":"end"});
                     $("#questions").off("click",".ques-detail .options");
                    scoreObj["end"][type] = level["max"];
                    $ui.nodeInit({"id":"#node","data":level});
                    var score = _this.getScore(scoreObj,type,level["basic"]*1,level["max"]*1);
                    $("#tabs>div.selected-tab").find("span").eq(1).html(score);
                    //跳转到下一项：
                    var i = notQues == "运动" ? 1:0;
                    $("#tabs>div").eq(i).removeClass("hide").addClass("selected-tab").siblings().addClass("hide").removeClass("selected-tab");
                    $("#tabs>div").eq(i).click(_this.tabCallback('#tabs>div.selected-tab',data,stageData,monthData,scoreObj));
                };
                var callFn0 = function(){};
                _this.dialog(tpl2,callFn22,callFn21,callFn0);
            }
        }
        if(startFlag){
            //顶点找到，顶点以前的默认完成；
            var quesType = type == "intellgence" ? "智力":"运动";
            for(var item in data[quesType]){
                for(var i = 0;i< data[quesType][item].length;i++){
                    if(!data[quesType][item][i].mr){
                        var idss= data[quesType][item][i].id;
                        if(idss.indexOf("T")>=0){
                            idss = idss.substring(0,idss.indexOf("T"));
                        }
                        if(idss*1 < level["basic"]*1){
                            data[quesType][item][i].value = 1;
                        }
                    }
                }
            }
            for(var i = 0;i< monthData[quesType].length;i++){
                idss= monthData[quesType][i].id;
                if(idss*1 < level["basic"]*1){
                    monthData[quesType][i].value = 1;
                }
            }
            for(var i = 1;i< level["basic"]*1;i++){
                if(!scoreObj[type][i]){
                    scoreObj[type][i]={"value" : 1}
                }
            }
        }
    };
    //遍历scoreObj:获取初始值为0的id
    var getInit0 = function(scoreObj,type){
        for(var item in scoreObj[type]){
            if(scoreObj[type][item].value == 0){
                return item;
            }
        }
    };
    //遍历scoreObj:startId的value值为1；
    var getEnd0 = function(scoreObj,type,startId){
        for(var item in scoreObj[type]){
            if(item == startId){
                if(scoreObj[type][item*1+1] && scoreObj[type][item*1+1].value == 0){
                    return item*1+1;//将值为1的后面的id
                }
            }
        }
    };
    //遍历scoreObj:获取初始值为0的前面的id
    var getInitBefore0 = function(scoreObj,type,idArr){
        var id;
        var min = Math.min.apply(null,idArr)*1;
        for(var item in scoreObj[type]){
            if(scoreObj[type][item].value == 0){
                if(item*1 == min){
                    id = min-1;
                }else{
                    var beforeItem = idArr[$.inArray(item,idArr)-1];
                    if( Math.abs(beforeItem*1 - item*1) == 1){
                        if(scoreObj[type][beforeItem] && scoreObj[type][beforeItem].value == 1){
                            id = item-1;
                            var j = 0;
                            do{
                                j++;
                            }while(scoreObj[type][id-j]);
                            id = id-j;
                        }else{
                            id = min-1;
                        }
                    }else{
                        id = beforeItem*1+1;
                    }
                }
                break;
            }
        }
        return id;
    };
    /*
    * 弹窗事件：
    * tpl:渲染弹窗的字段；
    * callback2 :按钮的flag==2 的回调函数；
    * callback1 :按钮的flag==1 的回调函数；
    * callback0 :按钮的flag==0 的回调函数；
    * params:其他参数
    * */
   event.dialog = function(tpl,callback2,callback1,callback0,params){
       $ui.dialogInit({"id":"#modal","data":tpl});
       $("#modal").off("click",".modal-footer>button");
       $("#modal").on("click",".modal-footer>button",function(){
           var flag = $(this).attr("flag");
           if(flag == "2"){
               if(callback2 && typeof callback2 == 'function'){
                   params ? callback2() : callback2(params);
               }
           }else if(flag == "1"){
                if(callback1 && typeof callback1 == 'function'){
                    params ? callback1() : callback1(params);
                }
           }else if(flag == "0"){
               if(callback0 && typeof callback0 == 'function'){
                   params ? callback0() : callback0(params);
               }
           }
       });
       $('#myModal').modal({backdrop: "static",keyboard:false,show:true});//点击背景空白处不会关闭；按下键盘esc不会被关闭
    };

    /*
    * 智龄计算：
    * */
    event.intelligenceAge = function(prevIntelligenceAge,diff){
        var age = 0;
        var lens = prevIntelligenceAge.length;
        if(prevIntelligenceAge.indexOf(">")>=0){
            age = prevIntelligenceAge.substring(prevIntelligenceAge.indexOf(">")+1,lens-1);
        }else if(prevIntelligenceAge.indexOf("<")>=0){
            age = prevIntelligenceAge.substring(prevIntelligenceAge.indexOf("<")+1,lens-1);
        }else{
            age = prevIntelligenceAge.substring(0,lens-1);
        }
        return (age*1 + diff/30).toFixed(1);
    };
    /*
    * 提交：
    **/
    event.getScore = function(scoreObj,type,startId,endId){
        var score = 0;
        for(var item in scoreObj[type]){
            if(item > startId && item <= endId){
                score += scoreObj[type][item].value*1;
            }
        }
        score = startId +score;
        return score;
    };
    /*
    *提交：
     */
    var submissionResult = function(){
        var params = $(this).data("params");
        var type = params.type,scoreObj = params.scoreObj,userId = params.userId;
        var mrScore = parseFloat($("#tabs>div").eq(0).find("span").eq(1).html()) >=0 ? $("#tabs>div").eq(0).find("span").eq(1).html() : 0;
        var prScore = parseFloat($("#tabs>div").eq(1).find("span").eq(1).html()) >=0 ? $("#tabs>div").eq(1).find("span").eq(1).html() : 0;
        var posId = {
            "score":{
                "mrScore": mrScore,
                "prScore":prScore
            },
            "height":$.trim($("#height").val()),
            "ques":scoreObj
        };
        var getScoreFn = function(result){
            $bb.openPage('bsidResult2',{
                "type":type,
                "userId":userId
            });
        };
        var scoreParams = $servers.scoreParams(type,posId,'',userId);
        var quesTypeArr = ["智力","运动","行为"];
        var notDo = [];
        for(var i=0;i<quesTypeArr.length;i++){
            if(quesTypeArr[i] == "行为"){
                if($.isEmptyObject(scoreObj["behavior"])){
                    notDo.push(quesTypeArr[i]);
                }
            }else{
                if($('#tabs>div[quesType="'+quesTypeArr[i]+'"]').attr("isEnd") !=  "end"){
                    notDo.push(quesTypeArr[i]);
                }
            }
        }
        if(notDo.length >= 2){
            $bb.toastShow(notDo.join('、')+"问卷还未做完，暂时不可以提交");
        }else if(notDo.length == 1){
            if($.inArray("行为",notDo)>=0){
                var callFn = function(){
                    $servers.getScore(scoreParams,getScoreFn);
                };
                $bb.toastConfirmShow(callFn,'',"行为量表未做，确定提交么？");
            }else{
                $bb.toastShow(notDo.join('、')+"问卷还未做完，请做完之后再提交");
            }
        }else{
            $servers.getScore(scoreParams,getScoreFn);
        }
    };
    event.getScoreClick = function(scoreObj,userId,type){
        var topbars = [
            {
                "icon":"fa fa-print",
                "name":"提交结果",
                "callback":submissionResult,
                "params":{"type":type,"scoreObj":scoreObj,"userId":userId}
            }
        ];
        $bb.toolbar(topbars);
    };
   return event;
});